
<?php
session_start();
ob_start();
if (isset($_SESSION["id"]))
    header("Location: http://localhost:82/trunghieu-web2/index.php?uid=" . $users[$index]['id']);
?>

<?php require_once 'model/users.php'; ?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="public/style.css">


<div class="page-form">
    <div class="login-form">
        <h1 class="header-form">Hu Tieu</h1>
        <div class="header-form-description">Don't use Virb yet? <u>Take the tour</u>  or <u>join now</u> </div>
        <form  method="POST">
            <div id="table_one">
                <table id="table">
                    <tr>
                        <td>Email Address:</td>
                        <td> <input id="firstname" type="text" name="username"></td>        
                    </tr>

                    <tr>
                        <td>Password:</td>
                        <td> <input id="password "type="password" name="password"></td>
                        <td><a href="">Forgot your  password</a> </td>
                    </tr>

                    <tr>
                        <td></td>
                        <td><input type="checkbox"/>remember me this on computer</td> 
                        <td><input type="submit" id="submit" name="submit" value="Login"></td>
                    </tr>
                </table>
            </div>
        </form>
        <div id="aaa">
        </div>
    </div>
</div>


<?php if (isset($_POST['submit'])) { ?>

    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $Yes = FALSE;
    $index1 = -1;
// dong lenh kiem tra use

    for ($i = 0; $i < count($users); $i++) {
        if ((strcmp($users[$i]['username'], $username) == 0 ) &&
                (strcmp($users[$i]['password'], $username) == 0 )) {
            $Yes = TRUE;
            $index1 = $i;
        }
    }
//xuat hien loi
    if ($Yes) {
//cau lenh dang nhap thanh cong
        $_SESSION["id"] = $users[$index1]["id"];
        header("Location: http://localhost:82/trunghieu-web2/index.php");
    } else {
        echo 'Dang Nhap that bai';
    }
}
?>

<?php ob_end_flush(); ?>